package com.jt.dify.websocket;

import com.jt.dify.service.AiService;
import org.noear.solon.ai.chat.ChatModel;
import org.noear.solon.annotation.Inject;
import org.noear.solon.net.annotation.ServerEndpoint;
import org.noear.solon.net.websocket.WebSocket;
import org.noear.solon.net.websocket.listener.SimpleWebSocketListener;

@ServerEndpoint("/chat")
public class ChatWebSocket extends SimpleWebSocketListener {

    @Inject
    ChatModel chatModel;

    @Inject
    AiService aiService;

    @Override
    public void onOpen(WebSocket socket) {

    }

    @Override
    public void onMessage(WebSocket socket, String text) {

        aiService.chat(socket, text);

    }

    @Override
    public void onClose(WebSocket socket) {
        super.onClose(socket);
    }

    @Override
    public void onError(WebSocket socket, Throwable error) {
        super.onError(socket, error);
    }
}